package com.cyt.web.controller.sys;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.sys.model.po.SysDictContent;
import com.cyt.sys.model.vo.SysDictContentVo;
import com.cyt.sys.service.SysDictContentService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @Author: YuShengQiang
 * @Date: 2018-11-22 10:00
 * @Description:角色控制层
 */
@RestController
public class SysDictContentController extends SysBaseController {

    @Resource
    private SysDictContentService sysDictContentService;

    /**
     * @Author: YuShengQiang
     * @Date: 2018-11-23 9:19
     * @Description:系统模块统一跳转处理
     */
    @RequestMapping("/sys/dictContent/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * @Author: YuShengQiang
     * @Date: 2018-11-23 14:19
     * @Description: 分页查询，page:当前页面，limit:页面大小
     */
    @BaseLog(module = "系统模块", classz = "字典管理", methods = "分页查询", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysDictContent/page", method = RequestMethod.POST)
    public ReturnResult page(SysDictContentVo sysDictContentVo, int limit, int page) {
        ReturnResult returnResult = sysDictContentService.page(sysDictContentVo, limit, page);
        return returnResult;
    }

    /**
     * @Author: YuShengQiang
     * @Date: 2018-11-23 14:19
     * @Description: 列表查询
     */
    @BaseLog(module = "系统模块", classz = "字典管理", methods = "列表查询", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysDictContent/list", method = RequestMethod.POST)
    public ReturnResult list(String dictType) {
        ReturnResult returnResult = sysDictContentService.list(new SysDictContentVo(dictType));
        return returnResult;
    }

    /**
     * @Author: YuShengQiang
     * @Date: 2018-11-23 14:19
     * @Description: 根据dictType获取集合, 多个以“，”隔开
     */
    @BaseLog(module = "系统模块", classz = "字典管理", methods = "根据dictType获取集合", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysDictContent/listByCode", method = RequestMethod.POST)
    public ReturnResult listByCode(String dictTypes) {
        ReturnResult returnResult = sysDictContentService.listByCode(dictTypes);
        return returnResult;
    }

    /**
     * @author: liufu zhu
     * @date: 2018/11/29 16:02
     * @Description: 跳转保存/更新页面
     */
    @RequestMapping(value = "/sysDictContent/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(SysDictContentVo sysDictContentVo) {
        ModelAndView view = new ModelAndView("/sys/dictContent/dictContentEdit");
        SysDictContent sysDictContent = new SysDictContent(sysDictContentVo.getDictType());
        if (StringUtils.isNotEmpty(sysDictContentVo.getId())) {
            sysDictContent = sysDictContentService.selectByPrimaryKey(sysDictContentVo.getId());
        }
        view.addObject(sysDictContent);
        return view;
    }

    /**
     * @author: liufu zhu
     * @date: 2018/11/29 16:10
     * @Description: 保存/更新字典数据
     */
    @BaseLog(module = "系统模块", classz = "字典管理", methods = "保存/更新字典数据", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysDictContent/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(SysDictContentVo sysDictContentVo) {
        ReturnResult result = sysDictContentService.addOrUpdate(sysDictContentVo);
        return result;
    }

    /**
     * @author: liufu zhu
     * @date: 2018/11/29 16:37
     * @Description: 删除字典数据
     */
    @BaseLog(module = "系统模块", classz = "字典管理", methods = "删除字典数据", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysDictContent/delete", method = RequestMethod.GET)
    public ReturnResult delete(String id) {
        return sysDictContentService.delete(id);
    }

}
